package com.tiantianfresh.view.service.impl;

import com.tiantianfresh.model.dao.AddressMapper;
import com.tiantianfresh.model.dao.OrderMapper;
import com.tiantianfresh.model.dao.OrderSpecificMapper;
import com.tiantianfresh.model.pojo.Address;
import com.tiantianfresh.model.pojo.Order;
import com.tiantianfresh.model.pojo.OrderAlipay;
import com.tiantianfresh.model.pojo.OrderSpecific;
import com.tiantianfresh.view.service.ShopCheckoutService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author FANGAO
 * @date 2021/12/4 - 下午 21:32
 */
@Service
public class ShopCheckoutServiceImpl implements ShopCheckoutService {

    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderSpecificMapper orderSpecificMapper;
    @Resource
    private AddressMapper addressMapper;

    @Override
    public List<OrderSpecific> queryChopCheckoutStateAll(Map<String,Object> map) {
        return orderSpecificMapper.queryChopCheckoutStateAll(map);
    }

    @Override
    public OrderAlipay payment(Map<String,Object> map) {
        if (orderMapper.payment(map)>0){
            System.out.println("----------------------");
            Order order = orderMapper.queryAlipayOrder(map);
            OrderAlipay orderAlipay = new OrderAlipay();
            orderAlipay.setOrderNo(order.getOrderid());
            orderAlipay.setAmount(order.getTotalPrice());
            return orderAlipay;
        }
        return null;
    }

    @Override
    public List<Address> queryAddressAll(Integer userid) {
        return addressMapper.queryAddressAll(userid);
    }

    @Override
    public boolean deleteShopcheckout(Map<String, Integer> map) {
        if (addressMapper.deleteShopcheckout(map)>0)return true;
        return false;
    }
}
